let fs = require('fs');
let path = require('path');
let dirPath = path.join(__dirname, 'template');

function getTemplateInfo(name) {
    var temp = {};
    fs.readdirSync(dirPath + '/' + name).forEach((file) => {
        if (/.js$/.test(file)) {
            var templateInfo = require(dirPath + '/' + name + '/' + file);
            for (let i in templateInfo) {
                temp[i] = templateInfo[i];
                temp[i]['templateId'] = i;
                temp[i]['type'] = Math.floor(i / 10000);
                if (templateInfo[i].name) {
                    propName[i] = templateInfo[i].name;
                }
            }
        }
    });
    return temp;
}

//所有模板信息
let totalConfig = {};
let propName = {}; //发送给客户端的信息 id => name
fs.readdirSync(dirPath).forEach((file) => {
    let stat = fs.lstatSync(dirPath + '/' + file);
    if (stat.isDirectory()) {
        totalConfig[file] = getTemplateInfo(file);
    }
});

exports.totalConfig = totalConfig;
exports.propName = propName;